home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / aSEPiA example source / Application / CScreenSaverWindow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  2.0 KB  |  104 lines  |  [TEXT/CWIE]

  1. /*---------------------------------------------------------------
  2.  
  3.     CScreenSaverWindow.cpp
  4.     
  5.     Window for drawing in from a plugin.
  6.  
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "CScreenSaverWindow.h"
  10. #include "CPluginManager.h"
  11. #include "IPluginDrawIntf.h"
  12. #include "HideShowMbar.h"
  13. #include <UWindows.h>
  14.  
  15. extern CPluginManager*    gPluginManager;
  16.  
  17.  
  18. CScreenSaverWindow::CScreenSaverWindow( LStream* inStream )
  19.     :LWindow( inStream ), mPlugin(0)
  20. {
  21.     mPlugin = gPluginManager->GetCurrentPlugin();
  22.     if ( mPlugin->Load() == noErr ) {
  23.         
  24.         mPlugin->GetInterfacePointer(IPluginDraw_ID, &mDrawIntf );
  25.  
  26.         SetUpWindow();
  27.         
  28.         Rect theRect;
  29.         CalcLocalFrameRect( theRect );
  30.         mDrawIntf->Initialize();
  31.         mDrawIntf->SetDrawingRect( theRect );
  32.         
  33.         
  34.         
  35.         StartRepeating();
  36.     } else {
  37.         throw;
  38.     }
  39. }
  40.  
  41. void CScreenSaverWindow::SetUpWindow()
  42. {
  43.     // resize the window to the whole screen
  44.     GDHandle    dominantDevice = UWindows::FindDominantDevice(
  45.                             UWindows::GetWindowStructureRect(GetMacPort()));
  46.  
  47.     if (dominantDevice == nil) {    // Window is offscreen, so use the
  48.                                     //   main scren
  49.         dominantDevice = ::GetMainDevice();
  50.     }
  51.     Rect        screenRect = (**dominantDevice).gdRect;
  52.     MoveWindowTo(0,0);
  53.     ResizeWindowTo( screenRect.right - screenRect.left,
  54.                                         screenRect.bottom - screenRect.top );
  55.  
  56.     // Hide the menu bar
  57.     HideShowMBAR( eHide );
  58.                                                 
  59. }
  60.  
  61. CScreenSaverWindow::~CScreenSaverWindow()
  62. {
  63.     FocusDraw();
  64.     mDrawIntf->Terminate();
  65.     
  66.     if ( mPlugin->IsLoaded() ) { // how could it be anything else
  67.         mPlugin->Unload();
  68.     }
  69.     
  70.     // show the menu bar
  71.     HideShowMBAR( eShow );
  72.     
  73. }
  74.  
  75. Boolean
  76. CScreenSaverWindow::HandleKeyPress(
  77.     const EventRecord    &inKeyEvent)
  78. {
  79.     // close the window
  80.     DoClose();
  81.     return true;
  82. }
  83.  
  84. void
  85. CScreenSaverWindow::ClickSelf(const SMouseDownEvent &inMouseDown)
  86. {
  87.     // close the window
  88.     DoClose();
  89. }
  90.  
  91. void
  92. CScreenSaverWindow::DrawSelf()
  93. {
  94.     Rect theRect;
  95.     CalcLocalFrameRect( theRect );
  96.     mDrawIntf->SetDrawingRect( theRect );
  97. }
  98.  
  99. void    CScreenSaverWindow::SpendTime( const EventRecord    &inMacEvent )
  100. {
  101.     FocusDraw();
  102.     mDrawIntf->DrawFrame();
  103. }
  104.